//
// Created by shaowenhan on 18/7/4.
//

#include "RandomSequence.h"

void generateRandomSequence(int* sequence, int n)
{
    int tmp, index;
    std::random_device rd;
    for(int i = 0; i < n-1; i++)
    {
        index = i + rd() % (n-i);
        tmp = sequence[index];
        sequence[index] = sequence[i];
        sequence[i] = tmp;
    }
}

// 需要用freeRandomSequence释放申请的空间
int* get0ToN_1RandomSequence(int n) {


    auto* res = new int[n];
    for(int i = 0; i < n; i++)
        res[i] = i;
    generateRandomSequence(res, n);
    return res;
}

void free0ToN_1RandomSequence(int** sequence)
{
    delete[] *sequence;
    *sequence = nullptr;
}

int getRandomNumberLessThanN(int n)
{
    std::random_device rd;
    return rd() % n;
}